#pragma once

#include "serial/serial.h"
#include "rclcpp/rclcpp.hpp"
#include "geometry_msgs/msg/pose2_d.hpp"
#include <iostream>
#include <vector>
#include <iomanip>
#include <sstream>

using namespace std;
using namespace rclcpp;

class communication : public rclcpp::Node
{
private:
    int sign = 1;
    // 串口初始化数据
    std::string serial_port_ = "/dev/DAP_LINK_2";
    int serial_baud_ = 115200;
    int serial_timeout_ = 15000;

    std::string pos_topic_ = "stpose2D";
    std::string leaser_pos = "leaserPOS2D";

    serial::Serial serial_;         // 声明串口对象
    geometry_msgs::msg::Pose2D POS; // 位姿

    // 声明发布者
    rclcpp::Publisher<geometry_msgs::msg::Pose2D>::SharedPtr pose_publisher_;
    // 声明订阅者
    rclcpp::Subscription<geometry_msgs::msg::Pose2D>::SharedPtr pose_subscription_;
    TimerBase::SharedPtr Timer_01;

public:
    communication();
    bool INIT();
    void Pose_Re_callback(geometry_msgs::msg::Pose2D::SharedPtr get_pos); // 订阅者回调函数
    void send_data(const uint8_t *data, size_t length);                   // 修改为接受指针和长度
    void receive_port(uint8_t h, uint8_t c, uint8_t l, uint8_t t);
    void Timer_Callback_01();
    int sendPacket(serial::Serial &serial, int16_t int_value, float float_value);

    ~communication();
};
